#include <vector>
#include <iostream>
#include <cstdlib>
#include "SDL.h"

/* VFUNGE: A C++ Befunge Visualizer/Interpreter in Two Dimensions */

/* DOCUMENTATION                                                  //
// Version 0.0.1a Features                                        //
//    fully functional Befunge interpreter                        //
//    loading files automatically from command line               //
//    non-graphical mode set in command line                      //
//    graphical Befunge program execution in SDL                  //
// Version 0.0.1a Documentation                                   //
//    class program:                                              //
//       stores characters in a vector vector after loading file  //
//       coordinate system is down-positive and right-positive    //
//       a given point (x,y) on the plane is program::at(x)[y]    //
//    function program::parse                                     //
//       executes program after load                              //
//    function program::load                                      //
//       loads program from file                                  */

/* SUSS/                 //
//   XX  |       | XX    //
//  X  X |       |   X X //
// X X X | XX    |  XXX  //
//  X    |   XX  |  X  X //
// X X X | X XXX | XX    //
//  X  X |  XXX  |  X  X //
//    XX |   XXX |  XXX  //
//  XX   |   X X |   X X //
//   X X |       | XX    //
// X X X |       |       //
//                 /SUSS */

class program: public vector< vector<char> >
{
   public:
      program(): x(0), y(0), dx(0), dy(0); // program starts at upper left and does not move unless commanded
      void parse();
      unsigned 
      
      vector<char> cstack;
      vector<int> istack;
      
      int x, y, dx, dy;
};

program::parse()
{
   while ( at(x)[y] != '@' ) // until end of program character is reached
   {
      // set direction
      switch ( at(x)[y] )
      {
      case '>':
         dx = 1;
         dy = 0;
         break;
      case 'v':
         dx = 0;
         dy = 1;
         break;
      case '<':
         dx = -1;
         dy = 0;
         break;
      case '^':
         dx = 0;
         dy = -1;
         break;
      
      // variables
      case '\"':
         // take a step to move into the program
         x += dx;
         y += dy;
         
         while ( at(x)[y] != '\"' )
         {
            cstack.push_back( at(x)[y] ); // pushes onto stack
         }
         
         break;
      
      // operations
      case ',':
         cout << cstack.back();
         cstack.pop_back();
         break;
      
      // conditions
      case '_':
         break;
      
      
      // increment the values of x and y accordingly
      x += dx;
      y += dy;
   }
}
